package MathCore;

import MathCore.Real;

public class CircularArrayInt extends Object
{
	private int elements [];
	private int entryPoint = 0;
	
	public CircularArrayInt(int len)
	{
		elements = new int [len];
		for(int i = 0; i<len; i++) elements[i] = 0;
	}
	
	public void addToEnd(int num)
	{
		elements[entryPoint % elements.length] = num;
		entryPoint++;
	}

	public void set(int pos, int val)
	{
		elements[(pos+entryPoint) % elements.length] = val;
	}
	
	public void reset()
	{
		entryPoint = 0;
	}
	
	public void addToStart(int num)
	{
		entryPoint--;
		if(entryPoint < 0 ) entryPoint += elements.length;
		
		elements[entryPoint % elements.length] = num;
	}

	public int get(int pos)
	{
		if(pos < 0 || pos > elements.length) return 0;
		return elements[(pos+entryPoint) % elements.length];
	}
	
	public int lenght()
	{
		return elements.length;
	}
	
}
